package com.skillworld.webapp.model.user;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Transient;
import org.hibernate.annotations.Immutable;

import com.skillworld.webapp.model.department.Department;

@Entity
@Immutable
@Table(name="UserDerived")
public class UserDerived 
{
    private long userId;
    User user;
    private int acceptedTutorials;
    private int validatedTutorials;
    private int students;
    private int createdCourses;
    private int coursesDone;
    private boolean coursesInAllDepts;

    protected UserDerived()
    {

    }

    @Id
    @Column(name="idUser")
    public long getUserId() 
    {
        return userId;
    }

    protected void setUserId(long userId)
    {
        this.userId = userId;
    }

    @OneToOne(mappedBy="derived",optional=false,fetch=FetchType.LAZY)
    protected User getUser()
    {
        return user;
    }

    protected void setUser(User user)
    {
        this.user = user;
    }

    @Column(name="acceptedTutorials")
    public int getAcceptedTutorials() 
    {
        return acceptedTutorials;
    }

    protected void setAcceptedTutorials(int acceptedTutorials) 
    {
        this.acceptedTutorials = acceptedTutorials;
    }
    
    @Transient
    public int getAcceptedTutorials(Department department)
    {
        return user.getDepartmentRank(department).getAcceptedTutorials();
    }
    
    @Column(name="validatedTutorials")
    public int getValidatedTutorials() 
    {
        return validatedTutorials;
    }

    protected void setValidatedTutorials(int validatedTutorials) 
    {
        this.validatedTutorials = validatedTutorials;
    }    
    
    @Column(name="students")
    public int getStudents() 
    {
        return students;
    }

    protected void setStudents(int students) 
    {
        this.students = students;
    }    

    @Column(name="createdCourses")
    public int getCreatedCourses() 
    {
        return createdCourses;
    }

    protected void setCreatedCourses(int createdCourses) 
    {
        this.createdCourses = createdCourses;
    }

    @Column(name="coursesDone")
    public int getCoursesDone() 
    {
        return coursesDone;
    }

    protected void setCoursesDone(int coursesDone) 
    {
        this.coursesDone = coursesDone;
    }

    @Column(name="coursesInAllDepts")
    public boolean getCoursesInAllDepts() 
    {
        return coursesInAllDepts;
    }

    protected void setCoursesInAllDepts(boolean coursesInAllDepts) 
    {
        this.coursesInAllDepts = coursesInAllDepts;
    }   
}
